package sdk.webview.fmc.com.fmcsdk.util;

import android.app.Application;

import java.lang.reflect.Method;

public class ReflectionUtils {
    public static Application getApplicationByReflection() {
        try {
            // 获取Class类对象
            Class<?> activityThreadClass = Class.forName("android.app.ActivityThread");
            // 获取方法
            Method currentApplicationMethod = activityThreadClass.getDeclaredMethod("currentApplication");
            // 由于这是私有方法，我们需要将其设为可访问
            currentApplicationMethod.setAccessible(true);
            // 调用方法，无需传入参数因为它是静态方法
            Application application = (Application) currentApplicationMethod.invoke(null);
            return application;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
